/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sv.com.intesal.clases.abstracts;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import sv.com.intesal.clases.auxiliar.cVarios;
import sv.com.intesal.conexion.cConexion;

/**
 *
 * @author ejerez
 */
public class ControladorAbstract {

    protected cVarios v;
    protected PreparedStatement ps;
    protected ResultSet rs;

    public ControladorAbstract() {
        this.v = new cVarios();
        this.ps = null;
        this.rs = null;
    }

    public PreparedStatement setPreparedStatement(String sql) throws Exception {
        try {
            return this.ps = cConexion.conectar().prepareStatement(sql);
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public void executeUpdate() throws Exception {
        try {
            this.ps.executeUpdate();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public void getExecuteQuery(String sql) throws Exception {
        try {
            this.rs = cConexion.conectar().prepareStatement(sql).executeQuery();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public void getExecuteQuery(PreparedStatement ps) throws Exception {
        try {
            this.rs = ps.executeQuery();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    public void setCloseConexion() throws Exception {
        try {
            if (ps != null) {
                this.ps.close();
            }
            if (rs != null) {
                this.rs.close();
            }
        } catch (Exception e) {
            throw new Exception(e);
        }
    }
}
